package com.team2.outpatient_sys.service.impl;

import com.team2.outpatient_sys.dao.PatientDao;
import com.team2.outpatient_sys.pojo.Patient;
import com.team2.outpatient_sys.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PatientServiceImpl implements PatientService {
    @Autowired
    PatientDao patientDao;

    @Override
    public boolean add(Patient patient) {
        String idCard = patient.getIdCard();
        String birth = idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14);
        patient.setBirth(birth);
        int gender = Integer.parseInt(String.valueOf(idCard.charAt(16)));
        if (gender % 2 == 0) {
            patient.setGender("女");
        } else {
            patient.setGender("男");
        }
        return patientDao.add(patient) < 1 ? false : true;
    }

    @Override
    public boolean update(Patient patient) {
        return patientDao.update(patient) < 1 ? false : true;
    }



    @Override
    public Patient findById(int id) {
        return patientDao.findById(id);
    }
}
